﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int f2count = 0;
        dbutils db = new dbutils();
        int type = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label2.Text = "";
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
        public void show1()
        {
            f2count--;
        }
        private void button1_Click(object sender, EventArgs e)
        {

            if (f2count == 1)
                return;
            string sql="select * from staff where loginname='"+textBox1.Text+"'";
            string re = db.loginsql(sql);
            if (re==null)
            {
                MessageBox.Show("登录失败！"+re);
                return;
            }
            MessageBox.Show("登录成功！" + re);
            
           
            f2count ++;
            Form2 f2 = new Form2();
            f2.setValue(int.Parse(textBox1.Text), re, this);
            
            //this.Hide();
            f2.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string constr = dbutils.constr;
            MySqlConnection mycon = new MySqlConnection(constr);
            mycon.Open();
            MySqlCommand mycmd = new MySqlCommand("insert into Persons(Id_P,name) values(1,'dikd3939')", mycon);
            if (mycmd.ExecuteNonQuery() > 0)
            {
                label1.Text="数据插入成功！";
            }
            
            mycon.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            label2.Text = "正在执行...请等待";

            string sql = "select * from admin where loginname='" + textBox1.Text+"'";
            string re = db.loginsql(sql);
            if (re == null)
            {
                MessageBox.Show("登录失败！" + re);
                return;
            }
            MessageBox.Show("登录成功！" + re);

            zg zzgg = new zg();
            zzgg.setValue(int.Parse(textBox1.Text), re, this);
            zzgg.Show();
            label2.Text = "";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            label2.Text = "正在执行...请等待";

            string sql = "select * from admin where loginname='" + textBox1.Text+"'";
            string re = db.loginsql(sql);
            if (re == null)
            {
                MessageBox.Show("登录失败！" + re);
                return;
            }
            MessageBox.Show("登录成功！" + re);

            admin ad = new admin();
            ad.setName(re);
            ad.Show();
            label2.Text = "";
        }
    }
}
